• 0

[c#] get the domain user is logged in to


Question

I am working on an app that will be installed at every machine for all of my companies clients, and basically it does/will do the following:

gets internal IP(s) of the machine

gets external IP of the machine

gets username currently logged in

gets computer name

--> get domain computer is on

and then the program basically just internally executes the link http://website/?ext=ext∫=int etc etc

then that page grabs all the vars and loads them into a sql database that we can search (some users have no idea what we mean when we try and get them to give us their IP...so we just ask for what they log in as, and we can search for it)

I would like to be able to add the domain to information sent, so that we can also group by company, but I cannot figure out how to do that...

Thanks!

Doug

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

I am not sure...i havent heard it referred to as dns domain before...but its like you have your windows server domain controller for domain XYZ, and you join that domain, so when you log in to the client, you dont log into the local machine, you log into XYZ, and thats the info I want to get (the XYZ)

Link to comment
Share on other sites

  • 0

alright I talked to Rus and he pointed me to the right place, thanks all for your help :)

public string getDomain()
  	{
    //Code given and modified with permission and courtesy of Ruslan Dzanmahmudov
    // Declare private variables.
    string nSearch = string.Format(@"SELECT * FROM Win32_ComputerSystem");
    ManagementObjectSearcher nSearcher = new ManagementObjectSearcher();

    // Set the properties.
    nSearcher.Query = new ObjectQuery(nSearch);
    ManagementObjectCollection nWMI = nSearcher.Get();

    // Parsing through all objects.
    foreach (ManagementObject _oManagement in nWMI)
    {
    	// Return the current clock speed.
    	return _oManagement["Domain"].ToString();
    }

    // Cannot get any information.
    return string.Empty;
  	}

Link to comment
Share on other sites

  • 0
alright I talked to Rus and he pointed me to the right place, thanks all for your help :)

public string getDomain()
 ?	{
 ? ?//Code given and modified with permission and courtesy of Ruslan Dzanmahmudov
 ? ?// Declare private variables.
 ? ?string nSearch = string.Format(@"SELECT * FROM Win32_ComputerSystem");
 ? ?ManagementObjectSearcher nSearcher = new ManagementObjectSearcher();

 ? ?// Set the properties.
 ? ?nSearcher.Query = new ObjectQuery(nSearch);
 ? ?ManagementObjectCollection nWMI = nSearcher.Get();

 ? ?// Parsing through all objects.
 ? ?foreach (ManagementObject _oManagement in nWMI)
 ? ?{
 ? ?	// Return the current clock speed.
 ? ?	return _oManagement["Domain"].ToString();
 ? ?}

 ? ?// Cannot get any information.
 ? ?return string.Empty;
 ?	}

586058698[/snapback]

<:laugh:br />That's WMI... :laugh:
Link to comment
Share on other sites

  • 0

I believe a call to

System.Security.Principal.WindowsIdentity.GetCurrent().Name

returns a string in the form of [domain]/[username]. This should return the user and domain information for the current user. A bonus is that it's all managed and you don't need to fiddle around with WMI.

Thinkz

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.